package com.fengdi.book.easy.String;

import java.util.ArrayList;

public class IsPalindrome {
    public boolean isPalindrome(String s) {
        /**
         * 1.先提取出所有的字母
         * 2.双指针
         * */
        if(s.length() <= 1) return true;

        ArrayList<Character> list = new ArrayList<>();

        for(char a : s.toCharArray()) {
            if(Character.isLetter(a) || Character.isDigit(a)) {
                list.add(Character.toLowerCase(a));
            }
        }

        int left = 0, right = list.size() - 1;
        while(left <= right) {
            if(list.get(left) != list.get(right)) {
                return false;
            }
            left++;
            right--;
        }

        return true;
    }
}
